# !/usr/bin/python
# _*_ coding: utf-8 _*_
# @Time : 2021/5/25 1:50 下午
# @Author : liujun
# @File : result.py
# @desc : 封装返回结果
from typing import Union

from fastapi import status
from fastapi.responses import JSONResponse, Response

from schemas.response.result_code import ResultCode


# 返回成功
def success(*, data: Union[list, dict, str]) -> Response:
    return JSONResponse(status_code=status.HTTP_200_OK,
                        content={'code': 1,
                                 'msg': '成功',
                                 'data': data
                                 }
                        )


# 返回失败
def failure(*, result_code: ResultCode) -> Response:
    # 获取返回结果
    value = result_code.value
    return JSONResponse(status_code=status.HTTP_200_OK,
                        content={'code': value(0),
                                 'msg': value(1)
                                 }
                        )

